package br.inf.solutions.apresentacoes.ssp.view.composer.hierarchy;

import org.springframework.context.annotation.Scope;
import org.zkoss.zk.ui.Component;

import br.com.vexillum.util.Message;
import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.hierarchy.HierarchyStructEntity;
import br.inf.solutions.apresentacoes.ssp.view.composer.PersonComposer;

@SuppressWarnings("serial")
@org.springframework.stereotype.Component
@Scope("prototype")
public class PersonHierarchyComposer extends HierarchyStructEntityComposer {

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		loadBinder();
	}
	
	public Return selectEntityInPerson() {
		Return ret = new Return(true);
		PersonComposer parent = (PersonComposer) arg.get("thisComposer");
		if(parent != null){
			HierarchyStructEntity unity = (HierarchyStructEntity) getTreeStructure().getSelectedItem().getValue();;
			if(unity == null){
				ret.setValid(false);
				ret.addMessage(new Message(null, getMessage("hierarchy_selectedunityentity_false")));
			}
			if(unity.getType().getName().equals("Unidade")){
				parent.getEntity().setUnity(unity);
				parent.loadBinder();
				getComponentById("treeModalWindow").detach();
			} else {
				ret.setValid(false);
				ret.addMessage(new Message(null, getMessage("hierarchy_selectedisunity_false")));
			}
		}
		return ret;
	}
}
